package com.msb.controller;

import com.msb.pojo.Book;
import com.msb.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class BookController {

    @Autowired
    private BookService bookService;


    @RequestMapping(value = "/findAll",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String findAll() {
//        System.out.println("findAll");
        List all = bookService.findAll();
        System.out.println("一共有"+all.size()+"b本书籍");
        String books = "";
        for (int i=0;i<all.size();i++) {
            Book book = (Book) all.get(i);
            books = books + book.getName();
            books = books + book.getAuthor();
        }
        System.out.println(books);
        return books;
    }
}
